<?php
/**
 * Fastapp.
 * 3/27/24
 * @Author deepsea
 * @Contact telegram:deepsea159
 */

namespace App\Fastapp\Api\Controller\Account;

use App\Fastapp\Api\Controller\ApiController;
use App\Fastapp\Api\Service\Account\RealnameService;
use App\Fastapp\Aspect\ApiAuth;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Http\Message\ResponseInterface;

#[Controller('api/realname'), ApiAuth]
class RealnameController extends ApiController
{
    #[Inject]
    public RealnameService $service;

    #[PostMapping('authentication')]
    public function authentication(): ResponseInterface
    {
        $data = $this->validate(self::RULE, [
            'code.*' => fastapp_t('account.v_14'),
            'id_no.*' => fastapp_t('account.v_15'),
            'surname.*' => fastapp_t('account.v_16'),
            'name.*' => fastapp_t('account.v_17'),
            'id_card_front.*' => fastapp_t('account.v_18'),
        ]);
        return $this->success($this->service->authentication($data));
    }

    #[GetMapping('check')]
    public function check(): ResponseInterface
    {
        return $this->success($this->service->check());
    }

    #[GetMapping('detail')]
    public function detail(): ResponseInterface
    {
        return $this->success($this->service->detail());
    }

    const RULE = [
        'code' => 'required',
        'type' => 'required|in:1,2,3,4',
        'id_no' => 'required',
        'surname' => 'required',
        'name' => 'required',
        'gender' => 'integer',
        'birthday' => 'date',
        'nation' => 'string',
        'address' => 'string',
        'issuing_authority' => 'string',
        'start_at' => 'required|date',
        'end_at' => 'date',
        'id_card_front' => 'required',
        'id_card_back' => 'string',
    ];
}